<template>
<h2>修改页面</h2>
<table border="1">
    <tr>
        <td>券类型</td>
        <td>
            <select v-model="Info.YouHuiTypeId">
                <option :value="0">--请选择--</option>
                <option v-for="item in Type" :value="item.TypeId">{{ item.TypeName }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>券标题</td>
        <td>
            <input type="text" v-model="Info.YouHuiName">
        </td>
    </tr>
    <tr>
        <td>券图片</td>
        <td>
            <input type="file" @change="UpLoad">
            <img style="width: 60px; height: 80px;" :src="Info.Img" >
        </td>
    </tr>
    <tr>
        <td>剩余库存</td>
        <td>
            <input type="number" v-model="Info.YouNum">
        </td>
    </tr>
    <tr>
        <td>减免金额</td>
        <td>
            <input type="number" v-model="Info.JianAmount">
        </td>
    </tr>
    <tr>
        <td>有效期</td>
        <td>
            <input type="date" v-model="Info.YouXiaoTime">--<input type="date" v-model="Info.EndTime">
        </td>
    </tr>
    <tr>
        <td>适用业务</td>
        <td>
           <select v-model="Info.Remark">
            <option value="订房">订房</option>
            <option value="堂食">堂食</option>
            <option value="订房,堂食">订房,堂食</option>
        
        </select>
           
        </td>
    </tr>
    <tr>
        <td>适用门店</td>
        <td>
            <select v-model="Info.ShopName">
                <option value="河北石家庄">河北石家庄</option>
                <option value="上海九州">上海九州</option>
                <option value="杭州美食">杭州美食</option>
                <option value="湖南横店">湖南横店</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>服务电话</td>
        <td>
            <input type="text" v-model="Info.FWPhone">
        </td>
    </tr>
    
    <tr>
        <td></td>
        <td>
            <input type="button" value="修改" @click="SaveData">
        </td>
    </tr>
   
</table>

</template>
<script setup lang="ts">

import axios from 'axios';
import { onMounted,ref } from 'vue';
import { useRoute ,useRouter} from 'vue-router';

//文件上传
const UpLoad=(e:any)=>{




}


const route=useRoute();
const router=useRouter();


onMounted(()=>{
    GetType();
    LoadData();
})


//反填
const LoadData=()=>{
    axios.get('https://localhost:7193/api/YouHui/GetYouHui',
    {
        params:{

            YouHuiId:route.params.id

        }
    }
    
    )

    .then(res=>{
        Info.value=res.data;
    })
}

const Type=ref([{
    TypeId:0,
    TypeName:""

}])
//下拉
const GetType=()=>{
    axios.get('https://localhost:7193/api/YouHui/GetYouHuiTypes')
    .then(res=>{
        Type.value=res.data;
    })
}

const Info=ref({
    YouHuiId:0,
    YouHuiName:"",
    YouXiaoTime:"",
    EndTime:"",
    ShopName:"",
    Img:"",
    YouNum:"",
    JianAmount:"",
    Remark:"",
    FWPhone:"",
    YouHuiTypeId:0,
    TypeName:""


})


const SaveData=()=>{

    if(Info.value.YouHuiName==""){
        alert("不能为空");
        return;
    }
    if(Info.value.YouNum==""){
        alert("剩余库存不能为空");
        return;
    }
    if(Info.value.JianAmount==""){
        alert("减免金额不能为空");
        return;
    }
    if(Info.value.YouXiaoTime==""){
        alert("有效时间不能为空");
        return;
    }
    if(Info.value.Remark==""){
        alert("适用业务不能为空");
        return;
    }
    if(Info.value.ShopName==""){
        alert("适用门店不能为空");
        return;
    }


    axios.put('https://localhost:7193/api/YouHui/UpdateYouHui',Info.value)
    .then(res=>{
        if(res.data>0){
            alert("修改成功");
            router.push("/ShowYouHui");

        }
        else{
            alert("修改失败");
        }
    })


}

</script>